<?php
defined('BASEPATH') or exit('No direct script access allowed');

if (! function_exists('passwordByEmail')) {

    function passwordByEmail($param)
    {
        $CI = & get_instance();
        $CI->load->helper('curl');
        $type = $param['type'];
        $username = $param['username'];
        /*
         * type值
         * 1.表示下发密码
         * 2.表示验证密码
         * username
         * 表示邮箱账号
         */
        $ip = getIP();
        switch ($type) {
            case 1:
                $interface = sprintf(HEXIN_EMAIL_PASSWORD, 'apply', HEXIN_EMAIL_SUBJECT, $ip, $username);
                break;
            case 2:
                $password = $param['password'];
                $interface = sprintf(HEXIN_EMAIL_PASSWORD . '/%s', 'cerify', HEXIN_EMAIL_SUBJECT, $ip, $username, $password);
                break;
            default:
                return false;
        }
        $result = curlByPost($interface);
        if ($result['info']['http_code'] == 200 && $result['data'] == 'OK') {
            return true;
        } else {
            return false;
        }
    }
}